package com.zhiwang.planet.mvp.p

import com.zhiwang.planet.di.ActivityScope
import com.zhiwang.planet.mvvm.model.RestApi
import com.zhiwang.planet.mvvm.model.request.SmsCodeRequest
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider
import com.zhiwang.planet.util.androidSchedule
import com.zhiwang.planet.util.responseVoidFunc
import javax.inject.Inject
import kotlin.reflect.KFunction1

@ActivityScope
class SmsCodePresenter @Inject constructor(var restApi: RestApi, var scopeProvider: AndroidLifecycleScopeProvider) {


    fun getWxBindSmsCode(phone: String, graphToken: String, graphCode: String, onSuccess: (() -> Unit), onError: ((String) -> Unit)) {

        val req = SmsCodeRequest(phone, graphCode, graphToken)
        req.setTypeRegister()
        val subscribe = restApi.getSmsCode(req)
                .androidSchedule()
                .responseVoidFunc()
                .subscribe({
                    onSuccess()
                }, {
                    onError(it.localizedMessage)
                }, {

                })
    }

    fun getPhoneBindSmsCode(phone: String, graphToken: String, graphCode: String, onSuccess: (() -> Unit), onError: ((String) -> Unit)) {

        val req = SmsCodeRequest(phone, graphCode, graphToken)
        req.setTypePhoneBind()
        val subscribe = restApi.getSmsCode(req)
                .androidSchedule()
                .responseVoidFunc()
                .subscribe({

                }, {
                    onError(it.localizedMessage)
                }, {
                    onSuccess()
                })
    }
}